﻿using Anke.SHManage.BLL;
using Anke.SHManage.MSSQLDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class LS_JJZXCHFCRWModeWebForm : System.Web.UI.Page
    {
        private string reportName; //2016-12-10 周志猛
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) //2016-12-10 周志猛
            {
                this.ReportViewer1.LocalReport.EnableHyperlinks = true;
                InitPage();

            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();

        }
        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 07:30:00");
            this.EndDate.Text = DateTime.Now.ToString("yyyy-MM-dd 07:30:00");

            if (Request.QueryString["ReportName"] != null) //2016-12-10 周志猛
            {
                reportName = Request.QueryString["ReportName"];
                ViewState["reportName"] = reportName;
            }
            else
            {
                reportName = "LS_ZDTFXZHSG.rdlc";
                ViewState["reportName"] = reportName;
            }
            if (reportName == "TJ_GRXFFSCG.rdlc") { this.StartDate.Text = DateTime.Now.ToString("yyyy-01-01 00:00:00"); }
            BindReportDataSource();
        }

        protected void BindReportDataSource()
        {
            DateTime beginTime = Convert.ToDateTime(this.StartDate.Text);
            DateTime endTime = Convert.ToDateTime(this.EndDate.Text);
            //string eventType = Convert.ToString(this.EventType.Text);
            string name = Convert.ToString(this.Name.Text);
            string centerID = Convert.ToString(this.Center.Text);
            string stationID = (this.Station.Text).ToString();
            //string diseasesClassification = (this.DiseasesClassification.Text).ToString();
            string doctorAndNurse = Convert.ToString(this.DoctorAndNurse.Text);
            string driver = Convert.ToString(this.Driver.Text);
            string stretcherBearersI = Convert.ToString(this.StretcherBearersI.Text);
            string alarmReason = Convert.ToString(this.AlarmReason.Text);
            //string illnessClassification = Convert.ToString(this.IllnessClassification.Text);
            string medicalJudge = Convert.ToString(this.MedicalJudge.Text);
            string localAddress = Convert.ToString(this.LocalAddress.Text);
            string sendAddress = Convert.ToString(this.SendAddress.Text);
            string dispatcher = Convert.ToString(this.Dispatcher.Text);

            string area = Convert.ToString(this.Area.Text);
            string helpType = Convert.ToString(this.HelpType.Text);
            string result = Convert.ToString(this.Result.Value);
            string banCi = Convert.ToString(this.BanCi.Value);
            string start1 = beginTime.ToString();
            string end1 = endTime.ToString();
            string time = Convert.ToString(this.Time.Text);
            //if(time=="")
            //{}
            //else { 
            //     time = Convert.ToString(this.Time.Text); 
            //}


            this.ReportViewer1.LocalReport.DataSources.Clear();
            //this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/LS_JJZXRW.rdlc");
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/" + reportName);

            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("startTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("endTime", end1);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed });
            string eventDispatchCenterID = UserOperateContext.Current.Seesion_Dispatch_SubCenterID; //2020-11-22 zch 登录人所处急救中心
            LSDAL dal = new LSDAL();
            switch (reportName)
            {
                case "LS_JJZXCHFCRW.rdlc"://急救中心迟缓放车任务流水表    
                    this.Page.Title = "急救中心迟缓放车任务流水表";
                    DataTable dt1 = dal.Get_LS_JJZXCHFCRW(beginTime, endTime, name, centerID, stationID, doctorAndNurse, driver, stretcherBearersI, alarmReason
                        , medicalJudge, localAddress, sendAddress, dispatcher, time, area, result, banCi, helpType, eventDispatchCenterID);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForLS_JJZXRW", dt1));
                    //任务小结还是用原来的方法
                    DataTable dt2 = dal.Get_LS_JJZXRWXJ(beginTime, endTime, name, centerID, stationID, doctorAndNurse, driver, stretcherBearersI
                        , alarmReason, medicalJudge, localAddress, sendAddress, dispatcher, time, area, result, banCi, eventDispatchCenterID);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForLS_JJZXRWXJ", dt2));
                    break;
                default:
                    break;
            }

            this.ReportViewer1.LocalReport.Refresh();
        }

    }
}